$.ready((function () {
    $.validator.setDefaults({
        submitHandler: function(form) {
            form.submit();
        }
    });

    // 姓名验证
    jQuery.validator.addMethod("username", function(value, element) {
        return this.optional(element) || /^[\u0391-\uFFE5\w]+$/.test(value);
    }, "只能包括中文字、英文字母、数字和下划线");

    // 手机号码验证
    jQuery.validator.addMethod("isMobile", function(value, element) {
        var length = value.length;
        var mobile =  /^1(3|5|8|4)\d{9}$/;
        return this.optional(element) || (length == 11 && mobile.test(value));
    }, "请正确填写您的手机号码");

    // 身份证号码验证
    jQuery.validator.addMethod("isIdCardNo", function(value, element) {
        var idcard_l = document.getElementById("idcard_l").checked;
        var passport = document.getElementById("passport_l").checked;
        if(idcard_l){
            var result = checkIDCard(value);
            document.getElementById("birthday").value="";
            if(result){
                var birthday = value.substring(6,14);
                birthday = birthday.substring(0,4)+"-"+birthday.substring(4,6)+"-"+birthday.substring(6,8);
                document.getElementById("birthday").value=birthday;
            }
            return this.optional(element) || result;
        }
        if(passport){
            //alert("paass");

//            var result;
//            var Expression=/(P\d{7})|(G\d{8})/;
//            var objExp=new RegExp(Expression);
//            if(objExp.test(value)==true){
//                result = true;
//            }else{
//                result = false;
//            }
            //var result = $(element).val();

            return this.optional(element) || true;
        }

    }, "请正确输入您的身份证号码");
    //护照编号验证
    jQuery.validator.addMethod("passport", function(value, element) {
        return this.optional(element) || function(value){
            var str=number;
            //在JavaScript中，正则表达式只能使用"/"开头和结束，不能使用双引号
            var Expression=/(P\d{7})|(G\d{8})/;
            var objExp=new RegExp(Expression);
            if(objExp.test(str)==true){
                return true;
            }else{
                return false;
            }
        };
    }, "请正确输入您的护照编号");
    // 联系电话(手机/电话皆可)验证
    jQuery.validator.addMethod("isPhone", function(value,element) {
        var length = value.length;
        var mobile =  /^1(3|5|8|4)\d{9}$/;
        var tel = /^\d{3,4}-?\d{7,9}$/;
        return this.optional(element) || (tel.test(value) || mobile.test(value));
    }, "请正确填写紧急联系电话");

    // 中文字两个字节,匹配字节长度
    jQuery.validator.addMethod("byteRangeLength", function(value, element, param) {
        var length = value.length;
        for(var i = 0; i < value.length; i++){
            if(value.charCodeAt(i) > 127){
                length++;
            }
        }
        return this.optional(element) || ( length >= param[0] && length <= param[1] );
    }, "请确保输入的值在3-15个字节之间(一个中文字算2个字节)");

    //只限制输入中文
    jQuery.validator.addMethod("stringCheck", function(value, element) {
        return this.optional(element) || /^[\u4e00-\u9fa5]+$/.test(value);
    }, "只能输入汉字");

    //只限制输入数字
    jQuery.validator.addMethod("number", function(value, element) {
        return this.optional(element) || /^[0-9]*$/.test(value);
    }, "只能输入数字");


    //email 惟一验证
    jQuery.validator.addMethod("isUnicueEmail", function(value, element) {

        if(emailVal == value){
            return this.optional(element) || true;
        }

        var emailURL = '<?=Util_BaseUrls::ajax_is_email_used()?>';
        var result = false;
        jQuery.ajax({
            async:false,
            url:emailURL,
            data:{'email':value},
            type:'post',
            success:function (data) {
                var data = eval('(' + data + ')');

                if(data.errcode){//存在员工档案

                    result = false;
                    return;
                }
                result = true;
                return;
            }
        });




        return this.optional(element) || result;
    }, "邮箱重复");


    objValidator = $('#form-horizontal').validate({

        rules: {
            username: {
                required:true,
                byteRangeLength:[1,10]
            },
            isIdCardNo:{
                required:true,
                isIdCardNo:true,
                passport:true,
                byteRangeLength:[0,20]
            },
            phone:{
                //required:true,
                isPhone:true

            },
            email:{
                //required:true,
                email:true,
                isUnicueEmail:true
            },
            isPhone:{
                //required:false,
                isPhone:true
            },
            native_place:{
                required:false,
                byteRangeLength:[0,20]
            },
            cordAdd:{
                required:false,
                byteRangeLength:[0,100]
            },
            xianju:{
                required:false,
                byteRangeLength:[0,100]
            },
            bisch:{
                required:false,
                byteRangeLength:[0,40]
            },
            zhuanye:{
                required:false,
                byteRangeLength:[0,40]
            },
            byteRangeLength:{
                required:false,
                byteRangeLength:[0,40]
            },
            updateName:{
                required:false,
                byteRangeLength:[0,10]
            },
            bank:{
                required:false,
                byteRangeLength:[0,20]
            },
            address:{
                required:true,
                stringCheck:true,
                byteRangeLength:[3,100]
            },
            card:{
                required:true,
                isIdCardNo:true

            },
            passport:{
                required:true,
                passport:true

            },
            positionName:{
                required:true
                //byteRangeLength:[0,40]
            },
            workCity:{
                required:true
            },
            startWorkTime:{
                required:true
            },
            directlyLeader:{
                required:true,

                byteRangeLength:[0,40]
            },
            inDirectLeader:{
                byteRangeLength:[0,40]
            },
            ptPositionName:{
                byteRangeLength:[0,40]
            },
            dpDirectlyLeader:{
                byteRangeLength:[0,40]
            },
            dpInDirectlyLeader:{
                byteRangeLength:[0,40]
            },
            englishname:{
                byteRangeLength:[0,20]
            }

        },
        messages:{
            username: {
                required: "请填写用户名",
                byteRangeLength: "最多只能输入5个中文字符"
            },
            isIdCardNo:{
                required:"请输入标识信息",
                isIdCardNo:"请输入合法的证件号码",
                byteRangeLength:"最多只能输入20个字符"
            },
            phone:{
                required: "请输入您的联系电话",
                isPhone: "请输入一个有效的联系电话"
            },
            email:{
                isUnicueEmail: "邮箱已存在",
                email: "请输入一个有效的Email地址"
            },
            isPhone:{
                isPhone: "请输入一个有效的联系电话"
            },
            native_place:{
                byteRangeLength:"最多只能输入10个中文字符"
            },
            cordAdd:{
                byteRangeLength:"最多只能输入50个中文字符"
            },
            xianju:{
                byteRangeLength:"最多只能输入50个中文字符"
            },
            zhuanye:{
                byteRangeLength:"最多只能输入20个中文字符"
            },
            bisch:{
                byteRangeLength:"最多只能输入20个中文字符"
            },
            englishname:{
                byteRangeLength:"最多只能输入20个英文字符"
            },
            updateName:{
                byteRangeLength:"最多只能输入5个中文字符"
            },
            bank:{
                byteRangeLength:"最多只能输入10个中文字符"
            },
            address:{
                required: "请输入您的联系地址",
                stringCheck: "请正确输入您的联系地址",
                byteRangeLength: "请详实您的联系地址以便于我们联系您"
            },
            card:{
                required:"请输入身份证号",
                isIdCardNo:"请输入正确的身份证号"
            },
            passport:{
                required:"请输入护照编号",
                passport:"请输入正确的护照编号"
            },
            positionName:{
                required:"请输入职位名称"
                //byteRangeLength:"最多只能输入20个中文字符"
            },
            workCity:{
                required:"请选择工作城市"
            },
            startWorkTime:{
                required:"开始担任本职日期不能为空"
            },
            directlyLeader:{
                required:"直属上级不能为空",
                byteRangeLength:"最多只能输入20个中文字符"
            },
            inDirectLeader:{
                byteRangeLength:"最多只能输入20个中文字符"
            },
            ptPositionName:{
                byteRangeLength:"最多只能输入20个中文字符"
            },
            dpDirectlyLeader:{
                byteRangeLength:"最多只能输入20个中文字符"
            },
            dpInDirectlyLeader:{
                byteRangeLength:"最多只能输入20个中文字符"
            }

        },
        errorPlacement:function (error, element) {
            if (element.is(":radio"))
                error.appendTo(element.parent().next().next()); else if (element.is(":checkbox"))
                error.appendTo(element.next()); else
                element.parent().append(error);
        }
    });

//身份证 url
    var isIdCardNoVal = $("input[name='isIdCardNo']").val();
    $("input[name='isIdCardNo']").bind('blur',function(){
        var obj =$(this);
        var type = $("input[name='unique_type']:checked").val();
        var number = $("input[name='isIdCardNo']").val();
        if(isIdCardNoVal == number){
            return;
        }
        var ajaxUnique ='<?=Util_BaseUrls::ajax_id_card()?>';
        jQuery.ajax({
            async:true,
            url:ajaxUnique,
            data:{'card_type':type,'id_card':number},
            type:'post',
            success:function (data) {
                var data = eval('(' + data + ')');
                if(data.errcode){//存在员工档案
                    $("#lab_exist_id").remove();
                    var html = '<label id="lab_exist_id" style="font-size: 12px;display: inline;color: red;">已存在该员工档案<a target="_blank" style="padding-left: 20px" href="'+data.data+'">查看</a></label>';
                    $(html).insertAfter(obj);
                    return;
                }
                $("#lab_exist_id").remove();
                result = false
                return;

            }
        });

    });
    //搜索职位
    function positionNameAuto(){
    $("input[name='positionName'],input[name='ptPositionName[]']").autocomplete({
        source: function(request, response) {
            var ajaxUrl2 = '<?=Util_BaseUrls::ajax_search_job()?>';
//            var testdata = [{job_name:'职位名称',depart_attr:'部门属性1',job_id:'1'},{job_name:'职位名称',depart_attr:'部门属性2',job_id:'2'},{job_name:'职位名称2',depart_attr:'部门属性3',job_id:'3'},{job_name:'职位名称',depart_attr:'部门属性4',job_id:'4'}];
//            testdata.push({job_name:'职位名称',depart_attr:'部门属性1',job_id:'1'},{job_name:'职位名称',depart_attr:'部门属性2',job_id:'2'},{job_name:'职位名称2',depart_attr:'部门属性3',job_id:'3'},{job_name:'职位名称',depart_attr:'部门属性4',job_id:'4'});
//            testdata.push({job_name:'职位名称',depart_attr:'部门属性1',job_id:'1'},{job_name:'职位名称',depart_attr:'部门属性2',job_id:'2'},{job_name:'职位名称2',depart_attr:'部门属性3',job_id:'3'},{job_name:'职位名称',depart_attr:'部门属性4',job_id:'4'});

            var packcity = $("select[name='packcity']").find("option:selected").text();//city
            $.ajax({
                url:ajaxUrl2,
                dataType: "json",
                data: {
                    city:packcity,
                    name: request.term

                },
                success: function(data) {
                    response( $.map( data.data, function( item ) {
                    //response( $.map( testdata, function( item ) {
                        return {
                            label:  item.job_name,
                            value:  item.job_name ,
                            id:  item.job_id,
                            cityID:item.city_id,
                            cityName:item.city_name

                        }
                    }));
                }
            });
        },
        select: function( event, ui ) {
            var id = ui.item.id;
            $(this).nextAll().remove();
            ui.item && $(this).parent().find('input[type="hidden"]').val(id);
            $(this).css("border","1px solid #CCCCCC");
            $("#work_city_name").val(ui.item.cityName);
            $("#work_city_id").val(ui.item.cityID);

        }
    })
    }
    //搜索员工
    function directlyLeaderHandler(){
    $("input[name='directlyLeader'],input[name='dpDirectlyLeader[]']").autocomplete({
        source: function(request, response) {
            var ajaxUrl2 = '<?=Util_BaseUrls::ajax_search_user()?>';
                $.ajax({
                url:ajaxUrl2,
                dataType: "json",
                data: {
                    name: request.term
                },
                success: function(data) {
                    response( $.map( data.data, function( item ) {
//                    response( $.map( testdata, function( item ) {
                        return {
                            label:  item.name ,
                            value:  item.name,
                            job_name: item.job_name,
                            user_id:  item.user_id,
                            job_id :item.job_id
                        }
                    }));
                }
            });
        },
        select: function( event, ui ) {
            var user_id = ui.item.user_id;
            var job_id = ui.item.job_id;
            ui.item && $(this).prev().val(job_id);
            ui.item && $(this).prev().prev().val(user_id);
            $(this).css("border","1px solid #CCCCCC");

        }
    });
    }
    function inDirectLeaderHandler(){
        $("input[name='noinDirectLeader[]'],input[name*='dpInDirectlyLeader']").autocomplete({
            source: function(request, response) {
                var ajaxUrl2 = '<?=Util_BaseUrls::ajax_search_user()?>';
                     $.ajax({
                    url:ajaxUrl2,
                    dataType: "json",
                    data: {
                        name: request.term
                    },
                    success: function(data) {
                        response( $.map( data.data, function( item ) {
                            //                    response( $.map( testdata, function( item ) {
                            return {
                                label:  item.name ,
                                value:  item.name,
                                job_name: item.job_name,
                                user_id:  item.user_id,
                                job_id :item.job_id
                            }
                        }));
                    }
                });
            },
            select: function( event, ui ) {
                var user_id = ui.item.user_id;
                var job_id = ui.item.job_id;
                ui.item && $(this).parent().find("input[type='hidden']:eq(1)").val(user_id);
                ui.item && $(this).parent().find("input[type='hidden']:eq(2)").val(job_id);
            }
        });
    }

    //添加虚线主管
    $(".addIndirectLeader").bind('click',addIndirectLeaderHandler);
    function addIndirectLeaderHandler(){
        var $html = $(this).parent().parent().clone();
        var delHtml = '<a class="delIndirectLeader" href="javascript:void(0)">--删除虚线主管</a>';

        $(delHtml).insertAfter($(this));
        $html.find("input").val("");
        if($(this).parent().parent().parent().parent().attr("title")){

        }
        $html.insertAfter($(this).parent().parent());
        $(this).remove();
        $(".addIndirectLeader").bind('click',addIndirectLeaderHandler);
        $("input[name='inDirectLeader[]'],input[name='dpInDirectlyLeader[]']").unbind();
        inDirectLeaderHandler();
        $(".delIndirectLeader").bind('click',delIndirectLeaderHandler);

    }
    function delIndirectLeaderHandler(){
        $(this).parent().parent().remove();
    }
    inDirectLeaderHandler();
    directlyLeaderHandler();
    positionNameAuto();
    //删除兼职信息  编辑页出现事件
//    $("#delDpartPosition").bind('click',function(){
//        $("#confirmDialog").modal();
//        $(".btn.btn-small.btn-primary.delok").bind('click',function(){
//            var obj = $(this);
//            var delPositionUrl = '<?=Util_BaseUrls::ajax_search_job()?>';//URL 没有明确
//            var jobID = $("input[name='ptPositionNameID']").val();
//            var number = $("input[name='isIdCardNo']").val();
//            jQuery.ajax({
//                url:delPositionUrl,
//                data:{'jobID':jobID,'number':number},
//                type:'post',
//                success:function (result) {
//                    var data = eval('(' + result + ')');
//                    if (data.errcode) {
//                        obj = obj.parent().parent();
//                        obj.remove();
//                        return;
//                    }
//                    $("#alertDialog").find(".modal-body").text(data.msg);
//                    $("#alertDialog").modal();
//
//                }
//            });
//
//        });
//
//
//    });


    //添加兼职信息事件

    $("#addDpartPosition").bind('click',addDepartPositionBlockHandler);
    function addDepartPositionBlockHandler(){
        var html = $(this).parent().clone();
        html.css("margin-top","30px");
        html.css("background","#fff");
        html.children("div:eq(2)").nextAll().remove();
        var str1 = '<div class="control-group"><label class="control-label">虚线主管：</label><div class="controls"><input type="hidden" name="xxRelationId[0][]">';
        var str2 ='<input type="hidden" name="dpInDirectlyLeaderID[0][]" class="ui-autocomplete-input" autocomplete="off"><span role="status" aria-live="polite" class="ui-helper-hidden-accessible"></span>';
        var str3 =' <input type="hidden" name="dpInDirectlyLeaderJobID[0][]" class="ui-autocomplete-input" autocomplete="off"><span role="status" aria-live="polite" class="ui-helper-hidden-accessible"></span>';
        var str4 =' <input type="text" placeholder="" class="byteRangeLength ui-autocomplete-input" name="dpInDirectlyLeader[0][]" autocomplete="off"><span role="status" aria-live="polite" class="ui-helper-hidden-accessible"></span><a href="javascript:void(0)" class="addIndirectLeader">+添加虚线主管</a>';
        var str5 =' </div> </div>';





        var str ='<div class="control-group"><label class="control-label">虚线主管：</label><div class="controls"><input type="hidden" name="xxRelationId[0][]"><input type="hidden" name="dpInDirectlyLeaderID[0][]"><input type="hidden" name="dpInDirectlyLeaderJobID[0][]"><input type="text" placeholder="" class="byteRangeLength" name="dpInDirectlyLeader[0][]"><a href="javascript:void(0)" class="addIndirectLeader">+添加虚线主管</a></div></div>';
        str = str1+ str2 + str3+str4+str5;

        var lefta = '<a class="a_del" href="javascript:;" style="top:30px;" id="delDpartPosition">删除兼职信息</a><a class="a_del" href="javascript:;"   id="addDpartPosition">添加兼职信息</a>';
        html.append(str);
        html.append(lefta);
        html.find("input").val("");
        var maxnum =parseInt($("#depart_max_num").val());
        maxnum = maxnum + 1;
        $("#depart_max_num").val(maxnum);
        var xxRelationId = html.children("div:last").children("div").children("input:eq(0)").attr("name");
        var user_id = html.children("div:last").children("div").children("input:eq(1)").attr("name");
        var job_id = html.children("div:last").children("div").children("input:eq(2)").attr("name");
        var name = html.children("div:last").children("div").children("input:eq(3)").attr("name");
        var jzwork_id = html.find(".input-append").children("input:first").attr("name");
        xxRelationId = xxRelationId.replace(/(\d+)/, function () {
            return maxnum;
        });
        user_id = user_id.replace(/(\d+)/, function () {
            return maxnum;
        });
        job_id = job_id.replace(/(\d+)/, function () {
            return maxnum;
        });
        name = name.replace(/(\d+)/, function () {
            return maxnum;
        });
        jzwork_id = jzwork_id.replace(/(\d+)/, function () {
            return maxnum;
        });
        html.children("div:last").children("div").children("input:eq(0)").attr("name",xxRelationId);
        html.children("div:last").children("div").children("input:eq(1)").attr("name",user_id);
        html.children("div:last").children("div").children("input:eq(2)").attr("name",job_id);
        html.children("div:last").children("div").children("input:eq(3)").attr("name",name);
        html.find(".input-append").children("input:first").attr("name",jzwork_id);
        $(html).insertAfter($(this).parent());
        $(".addIndirectLeader").bind('click',addIndirectLeaderHandler);
        $("#addDpartPosition").unbind();
        $(this).prev().css("top","10px");
        $(this).remove();
        directlyLeaderHandler();
        $("#addDpartPosition").bind('click',addDepartPositionBlockHandler);
        $(".a_del").bind('click',delDepartPositionBlockHandler);
        positionNameAuto();
        inDirectLeaderHandler();
        $("div[title='兼职信息']").children(".panel_normal.panel_hover").bind('mouseover',function(){
            $(this).find("#delDpartPosition").show();
            $(this).css("background","#F9F9F9");
        });
        $("div[title='兼职信息']").children(".panel_normal.panel_hover").bind('mouseout',function(){
            $(this).find("#delDpartPosition").hide();
            $(this).css("background","#FFFFFF");
        });

        clearHiddenValue();
        $("input[name='jzstarttime[]']").datepicker();
        $(".icon-calendar").bind('click',function(e){
            //$('#datepicker').trigger('focus.Datepicker');
            $(this).parent().prev().trigger('click');
            e.stopPropagation();
        });
        //inDirectLeaderHandler();

    }
    $("#delDpartPosition").bind('click',delDepartPositionBlockHandler);
    function delDepartPositionBlockHandler(){
        var num = $(this).next().length;
        if(num){
            var a_add = $(this).next();
            var temp
            if($(this).parent().prev().length > 0){
                 var obj = $(this).parent().prev().children("a");
                obj.css("top","30px");
                 $(a_add).insertAfter(obj);
                $("#delDpartPosition").bind('click',delDepartPositionBlockHandler);

            }
        }
        $(this).parent().remove();
    }

    //编辑页出现
    $("div[title='兼职信息']").children(".panel_normal.panel_hover").bind('mouseover',function(){
        $(this).find("#delDpartPosition").show();
        $(this).css("background","#F9F9F9");
    });
    $("div[title='兼职信息']").children(".panel_normal.panel_hover").bind('mouseout',function(){
        $(this).find("#delDpartPosition").hide();
        $(this).css("background","#FFFFFF");
    });
    var emailVal =  $("input[name='email']").val();
//    $("input[name='email']").bind('blur',function(){
//        var obj = $(this);
//        if(emailVal == obj.val()){
//            return;
//        }
//        if(!$.trim(obj.val())){
//            return;
//        }
//        if( (obj.nextAll().length >0 &&obj.next().css("display") != "none")){
//            return;
//        }
//        var email = $.trim($(this).val());
//        var emailURL = '<?=Util_BaseUrls::ajax_is_email_used()?>';
//        jQuery.ajax({
//            async:true,
//            url:emailURL,
//            data:{'email':email},
//            type:'post',
//            success:function (data) {
//                var data = eval('(' + data + ')');
//                if(data.errcode){//存在员工档案
//                    obj.nextAll().remove();
//                    var html = '<label style="display: inline;color: red;">邮箱已被使用</label>';
//                    $(html).insertAfter(obj);
//                    return;
//                }
//                obj.nextAll().remove();
//                var html = '<label style="display: inline;color:green;">邮箱可用</label>';
//                $(html).insertAfter(obj);
//            }
//        });
//
//    });
//    $("input[name='email']").bind('focus',function(){
//        var obj = $(this);
//        obj.nextAll().remove();
//    });

    //返回员工编号
    $("select[name='packcity'],select[name='user_type']").bind('change',createWorkNumber);
    //生成员工工号
    function createWorkNumber(){
        var url =  '<?=Util_BaseUrls::ajax_user_code()?>';
        var city_id =  $("select[name='packcity']").val();
        var user_type = $("select[name='user_type']").val();
        if(city_id != '请选择' && user_type != '请选择' ) {
            jQuery.ajax({
                url:url,
                data:{'city_id':city_id,'user_type':user_type},
                type:'post',
                success:function (result) {
                    var data = eval('(' + result + ')');
                    if (data.errcode ==1) {
                        $("input[name='user_code']").val(data.data);
                        $('.user_code').html(data.data);
                        return;
                    }


                }
            });

        }
    }
    function clearHiddenValue(){
    $("input[name='positionName'],input[name='ptPositionName[]'],input[name='noinDirectLeader[]'],input[name='noinDirectLeader[]'],input[name*='dpInDirectlyLeader']").bind('change',function(){
       if(!$.trim($(this).val())){
           $(this).parent().children("input").val("");
       }
    });
    }
    clearHiddenValue();

    function dealEditPosition(){
        if(location.href.indexOf("user_id")>-1){
            var dela = '<a class="a_del" href="javascript:;" style="top:10px;" id="delDpartPosition">删除兼职信息</a>';
            var lefta = '<a class="a_del" href="javascript:;" style="top:30px;" id="delDpartPosition">删除兼职信息</a><a class="a_del" href="javascript:;"   id="addDpartPosition">添加兼职信息</a>';

            $("div[title='兼职信息']").children(".panel_hover").append(dela);
            $("div[title='兼职信息']").children(".panel_hover:last").children("a").remove();
            $("div[title='兼职信息']").children(".panel_hover:last").append(lefta);
            $("#addDpartPosition").bind('click',addDepartPositionBlockHandler);
            $(".delIndirectLeader").bind('click',delIndirectLeaderHandler);
            $("select[name='packcity'],select[name='user_type']").unbind();
        }
    }
    dealEditPosition();



})());





function checkIDCard(id) {
    var idNum = id;
    var errors = new Array(
        "验证通过",
        "身份证号码位数不对",
        "身份证含有非法字符",
        "身份证号码校验错误",
        "身份证地区非法"
    );
    //身份号码位数及格式检验
    var re;
    var len = idNum.length;
    //身份证位数检验
    if (len != 15 && len != 18) {
        return false;
        return errors[1];
    } else if (len == 15) {
        re = new RegExp(/^(\d{6})()?(\d{2})(\d{2})(\d{2})(\d{3})$/);
    } else {
        re = new RegExp(/^(\d{6})()?(\d{4})(\d{2})(\d{2})(\d{3})([0-9xX])$/);
    }

    var area = { 11: "北京", 12: "天津", 13: "河北", 14: "山西",
        15: "内蒙古", 21: "辽宁", 22: "吉林", 23: "黑龙江", 31: "上海",
        32: "江苏", 33: "浙江", 34: "安徽", 35: "福建", 36: "江西",
        37: "山东", 41: "河南", 42: "湖北", 43: "湖南", 44: "广东",
        45: "广西", 46: "海南", 50: "重庆", 51: "四川", 52: "贵州",
        53: "云南", 54: "西藏", 61: "陕西", 62: "甘肃", 63: "青海",
        64: "宁夏", 65: "新疆", 71: "台湾", 81: "香港", 82: "澳门",
        91: "国外"
    }

    var idcard_array = new Array();
    idcard_array = idNum.split("");

    //地区检验
    if (area[parseInt(idNum.substr(0, 2))] == null) {
        return false;
        return errors[4];
    }

    //出生日期正确性检验
    var a = idNum.match(re);

    if (a != null) {
        if (len == 15) {
            var DD = new Date("19" + a[3] + "/" + a[4] + "/" + a[5]);
            var flag = DD.getYear() == a[3] && (DD.getMonth() + 1) == a[4] && DD.getDate() == a[5];
        }
        else if (len == 18) {
            var DD = new Date(a[3] + "/" + a[4] + "/" + a[5]);
            var flag = DD.getFullYear() == a[3] && (DD.getMonth() + 1) == a[4] && DD.getDate() == a[5];
        }
        if (!flag) {
            //return false;
            return false;
            return "身份证出生日期不对！";
        }
        //检验校验位
        if (len == 18) {
            S = (parseInt(idcard_array[0]) + parseInt(idcard_array[10])) * 7
                + (parseInt(idcard_array[1]) + parseInt(idcard_array[11])) * 9
                + (parseInt(idcard_array[2]) + parseInt(idcard_array[12])) * 10
                + (parseInt(idcard_array[3]) + parseInt(idcard_array[13])) * 5
                + (parseInt(idcard_array[4]) + parseInt(idcard_array[14])) * 8
                + (parseInt(idcard_array[5]) + parseInt(idcard_array[15])) * 4
                + (parseInt(idcard_array[6]) + parseInt(idcard_array[16])) * 2
                + parseInt(idcard_array[7]) * 1
                + parseInt(idcard_array[8]) * 6
                + parseInt(idcard_array[9]) * 3;

            Y = S % 11;
            M = "F";
            JYM = "10X98765432";
            M = JYM.substr(Y, 1); //判断校验位

            //检测ID的校验位
            if (M == idcard_array[17]) {
                return true;
                //return "";
            }
            else {
                //return false;
                return false;
                return errors[3];
            }
        }

    } else {
        //return false;
        return false;
        return errors[2];
    }
    return true;
}
var submitnum = false;
$(".btn.btn-primary").bind('click',function(){
    if(!objValidator.form()){

        return false;
    }
    if(!$("input[name='positionNameID']").val()){
        $("input[name='positionName']").css("borderColor","red");
        return false;
    }
    if(!$("input[name='directlyLeaderJobID']").val()){
        $("input[name='directlyLeader']").css("borderColor","red");
        return false;
    }
    if(submitnum){
        alert("请勿重复提交");
        return false;
    }
    submitnum = true;

    return true;

});

